Repository navigation
Block Editor: Include resolved bound content when copying blocks - #84428
salvatorecorsi wants to merge 17 commits into
Conversation
🤖 PR meta 🤖👋 Welcome👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @salvatorecorsi! In case you missed it, we'd love to have you join us in our Slack community. If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information. 🎉 PropsIf you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
Updated as activity occurs, without notifying anyone named here. Add the 🏷️ LabelsThis pull request needs exactly one label indicating its type, and has 0.
Read more about Type labels in Gutenberg. If you cannot add labels yourself, a reviewer can do it for you. |
ciampo
left a comment
There was a problem hiding this comment.
I don't have the full context on the block bindings work, but I took a look from the menu and clipboard side and left a few comments inline. Please don't count me as the main reviewer for this one.
| : getClipboardBlocksContent( | ||
| getBlocksByClientId( clientIds ) as Block[], | ||
| registry, | ||
| attributesForCopy |
There was a problem hiding this comment.
Copying a bound List Item from an ordered list produces a bare <li> here. Could the rich menu copy honor requiresWrapperOnCopy so it retains the parent <ol> the same way keyboard copy does?
There was a problem hiding this comment.
The ordered list now pastes with its wrapper. I found one side effect for Paste styles. With a large bound List Item inside a small List, copying the item applies small to the target. Could we keep the wrapper for regular paste and use the selected item's styles for Paste styles?
There was a problem hiding this comment.
Paste styles now reads the selected item’s styles while normal paste keeps the ordered-list wrapper. A clipboard-only marker distinguishes a synthetic wrapper from an actually selected List and is removed before insertion, so copying the List itself still uses its own styles.
There was a problem hiding this comment.
The selected item’s styles now paste correctly. Pasting the new markup into an older editor adds a Classic block before the List. Could we put the marker inside the List’s opening block delimiter so older editors can ignore it?
There was a problem hiding this comment.
Good catch! The marker is now an extra attribute inside the synthetic List's opening block delimiter. An unaware parser can ignore it, and Paste styles can still distinguish that wrapper from a List the user selected. The regression parses the raw copied HTML without marker removal and gets one valid List, with no preceding Classic block.
There was a problem hiding this comment.
The marker inside the delimiter works with older editors now. The menu still adds the wrapper only when a bound value resolves, so the same List Item copies with or without its List depending on whether the data has loaded. Could Options → Copy use addWrapper: true like keyboard copy? Then the 'bound' mode could go.
There was a problem hiding this comment.
Options → Copy now always uses addWrapper: true, and the 'bound' mode is gone. A List Item keeps the same parent wrapper while its data loads; Paste styles still reads the item's styles.
|
Thanks for checking these clipboard paths. The update in 53cf427a tries the synchronous copy event first so the block comments can travel with the visible text. Paste styles reads the serialized HTML when available and still accepts the existing serialized text format. Menu copy keeps the ordered-list wrapper for a bound item, and unbound Copy and Cut reuse the same serialization. I verified the menu copy, pasting back with the binding, and Paste styles in the actual post editor in Chromium. The menu round trip is also in the WebKit Playwright project. My Windows WebKit 27.2 build did not return the rich clipboard payload even in a minimal copy-event control, so the Safari round trip still needs confirmation. |
| .filter( | ||
| ( [ attributeName, binding ] ) => | ||
| bindableAttributes?.includes( attributeName ) && | ||
| registeredSources[ binding?.source as string ] |
There was a problem hiding this comment.
With testing/server-only-source, the paragraph stores "paragraph default content" and the editor displays "Server Source". Copying the block now makes "Server Source" the pasted paragraph's saved content. Could we preserve the original fallback when the editor only has a placeholder? The existing server-only fixture would cover this.
There was a problem hiding this comment.
Thanks :D Server-only sources now stay out of the editor snapshot, because their displayed text is a placeholder rather than a value we can save. Copy retains the paragraph’s saved fallback; the regression covers a source without getValues.
There was a problem hiding this comment.
The server-only case is fixed. With the existing inaccessible core/post-meta field, copying still changes the paragraph’s saved text from fallback content to unaccessible_field. Could we keep the saved text when the source returns a field key for display?
There was a problem hiding this comment.
You're right — that key is a display placeholder, so it mustn't replace the saved fallback. Copy now resolves values with an optional isForCopy request, letting the source omit unavailable values while retaining genuine key/label matches and empty values. I verified Ctrl+C for your inaccessible post-meta case in the real post editor: the fallback and binding survive, and the source block stays unchanged. The callback addition is documented for API review.
There was a problem hiding this comment.
The post-meta case keeps its saved text now, thanks. core/term-data still returns its field label when the term isn't available. Copying a Navigation Link then saves "url":null, and a bound paragraph saves Name. Could term-data skip those values when isForCopy is set, the same way post-data does?
There was a problem hiding this comment.
Thanks :D core/term-data now omits unavailable fields for copy, so the saved fallback survives instead of a display key or label. Genuine values, including empty values and values equal to a label, are still copied.
| : getClipboardBlocksContent( | ||
| getBlocksByClientId( clientIds ) as Block[], | ||
| registry, | ||
| attributesForCopy |
There was a problem hiding this comment.
The ordered list now pastes with its wrapper. I found one side effect for Paste styles. With a large bound List Item inside a small List, copying the item applies small to the target. Could we keep the wrapper for regular paste and use the selected item's styles for Paste styles?
There was a problem hiding this comment.
Left some more feednack (I don't think any of these are blockinh), more like consistency fixes for the copy paths.
One optional simplification: edit.tsx always provides getAttributesForCopy, so it could be required. Then the computedAttributes fallback in getBoundAttributesForCopy and that dependency of the registration effect could go.
| blockContext.query !== undefined || | ||
| blockContext.queryId !== undefined |
There was a problem hiding this comment.
Copying a Terms Query saves the active row's term name into the template's paragraph fallback, so the copy depends on which row was active. Could we skip termQuery here too, next to query and queryId?
There was a problem hiding this comment.
I've added termQuery alongside query and queryId, including the effect dependencies, so a Terms Query row can't replace the template's saved fallback. The mounted BlockEdit test checks that no copy getter is registered in that context.
| The function must return an `object` with this structure: | ||
| `{ 'block attribute' : value }` | ||
|
|
||
| For copy requests, return the actual source values. Omit an attribute, or return `undefined` for it, when its value is unavailable and the editor displays a placeholder instead. This preserves the attribute's saved fallback in the copied block. Return genuine values even when they are empty, read-only, or equal to a field's key or label. |
There was a problem hiding this comment.
The wpmovies/visualization-date example above still returns today's date when the meta value is missing, so copying the block saves that date as its content. Could the example skip the value when isForCopy is set?
I'm also wondering if existing sources that don't know about isForCopy should opt in to copying resolved values. Without an opt-in, they'll start saving their placeholders.
There was a problem hiding this comment.
The date example now omits missing/null metadata on copy and keeps an actual empty string empty; its display still falls back to today's date. Sources must opt in with supportsCopy: true before they receive isForCopy requests, so existing sources keep their saved fallbacks. I also made the private getter required and removed the cached computedAttributes fallback and effect dependency.
What?
See #84362. Related to #84389, which guards the selected bound-field RichText copy path.
Include available client-resolved binding values when copying blocks from the canvas, List View and the options menu. Preserve binding definitions and each attribute's saved fallback when its source cannot provide a copyable value.
Why?
A bound paragraph can display content while its stored content is empty, producing an empty copy. A display-only field key or label can also overwrite a saved fallback. Resolving attributes independently matters for blocks such as Button: an available label should survive even when its bound URL is unavailable.
Clipboard transport must retain the block comments carrying bindings, including when an asynchronous write is needed before Cut can remove the source. Copying an individual List Item also needs its parent List for valid paste, while Paste styles needs the selected item's styles.
How?
Client binding sources explicitly opt in with the optional
supportsCopy: trueregistration property. Only an exacttrueallows the copy resolver to callgetValueswithisForCopy: true; absent or false preserves saved fallbacks. Registration rejects defined non-boolean values. This leaves existing sources' display behavior intact and lets opted-in sources omit attributes that only have display placeholders.The four built-in sources,
core/post-meta,core/post-data,core/pattern-overridesandcore/term-data, opt in. Unavailable term keys/labels and other display placeholders are omitted on copy; genuine values equal to their keys or labels, empty values and readable read-only values remain copyable. The documented date source also opts in: missing or null meta is omitted for copy, a genuine empty value stays empty, and display keeps its existing fallback to today's date.Eligible mounted block edits register a required, lazy copy getter in the existing per-editor refs context. Copy reads current values and applies only available bound attributes to cloned selected blocks. Each omitted attribute retains its saved fallback, with bindings and source blocks unchanged. Stale, duplicate, preview, Query Loop and Terms Query contexts are excluded. Rendering continues to use the display attributes; the private copy ref no longer stores a display snapshot fallback.
Canvas, List View and menu copies share the payload builder. For resolved bound values, the menu first tries a synchronous copy event for rich HTML and visible plain text; if unavailable, it writes the complete serialized markup as text. Other menu copies retain their serialized-text transport. Cut waits for a successful write before removing the source. Options Copy consistently requests wrappers for both bound and unbound List Items.
A clipboard-only property in the synthetic parent's opening delimiter identifies the wrapper without introducing a preceding Classic block in an unaware parser. Normal paste consumes only that marker and keeps the List; Paste styles uses the selected children. Copying an actual List uses its own styles. Marker insertion/removal preserves the other serialized attribute bytes. Windows fragment and Chromium metadata cleanup applies only to actual
text/html, preserving literal fragment comments in serialized plain-text payloads.Testing Instructions
Bound <strong>text</strong>. Custom client sources must registersupportsCopy: trueand return available values forisForCopyrequests. Copy from the canvas, List View and options menu; paste into Gutenberg and inspect the content, valid serialization andmetadata.bindings. Check that the original and its source are unchanged.fallback contentto the inaccessiblecore/post-metakeyunaccessible_field. Its displayed key must not replace the fallback. Repeat with an unavailable term field, an unaware custom source, genuine empty values and genuine values equal to a field key or label.<!--StartFragment-->and<!--EndFragment-->comments. Paste styles must preserve the Group's styles when the clipboard transport contains serialized plain text.Testing Instructions for Keyboard
Use Ctrl+C/Cmd+C and Ctrl+V/Cmd+V with block selections in the canvas and List View. Extend and reverse selections with the keyboard, and repeat with partial RichText endpoints. Focus a List View row, open its options menu with the keyboard, and activate Copy or Cut. Verify the source remains selected and present until a pending Cut write completes.
Historical validation — 24 November 2026
Published head:
57715250e3fc7c8e896ac7a1f40aa6d005c53c78, incorporating trunkf0dbebf61914de11d7f79a0e1558ed46dbfd5c14.usePasteStylesregistry dependency warning with the same dependency/member-use pattern as F0. Raw Markdown lint still reports the six unchanged MD060 diagnostics at line 126; that is a verified baseline exception, not a Markdown lint pass.The platform payload and unaware-parser controls are focused tests, not an older-WordPress or browser matrix. Genuine readable meta key/empty controls remain source tests; the native plan adds no readable meta schema or plugin. No Docker E2E, Safari/WebKit, full repository functional suite or human testing pass is claimed.
Screenshots or screencast
Not applicable: this changes clipboard payloads.
Could a maintainer add the
[Type] Buglabel? I do not have permission to apply upstream labels. The optionalsupportsCopyregistration property andisForCopycallback argument need API review; if accepted, could a maintainer addNeeds Dev Note?Branch update — 24 November 2026 (current trunk 6b92844)
Merged upstream trunk
6b928443b3df5480924958df2dcae0dae692dadbto resolve the actual package-changelog conflict. The original source and regression-test contribution is retained. Upstream release sections are preserved, with this PR's notes only in the current Unreleased categories, after upstream notes.Fresh validation on published head
794e519a0d54103f9a99f2a7e854af092168065e: verified reuse of this checkout’s isolated dependency installation, production build, PR changelog validation, full repository typecheck, the scoped lint/static-analysis checks, test conventions, tsconfig validation, generated-documentation checks passed. 308 focused test executions passed across 16 test-file executions. The documentation lint comparison reproduced only the same six MD060 diagnostics at the unchanged table row; this is a baseline comparison, not a Markdown lint pass. The three scoped published-dependency audits use the Windows junction adapter and remain separate from the default full audit; unchecked dynamic specifiers remain recorded in their result files.These are scoped checks, not a full repository functional-suite or Docker E2E pass. Fresh Chromium post-editor verification passed for the canvas, List View and menu clipboard paths. The owned draft, preferences, session, mount and server state were restored. Hosted CI and maintainer-only metadata checks are separate from these local results.
Use of AI Tools
OpenAI Codex assisted with investigation, implementation, regression tests, automated source review and validation, including the focused native-editor Chromium adapter. Maintainer review is requested.